﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SuperMarketSystem
{
    public partial class RestockerControl : UserControl
    {
        event RestockEventHandler restockEvent;
        event NewItemEventHandler newItemEvent;
        event FinishedEventHandler finishEvent;
        SelfCheckStation parent;

        public RestockerControl(SelfCheckStation p)
        {
            parent = p;
            InitializeComponent();
            restockEvent += parent.restockitemhandler;
            newItemEvent += parent.itemhandler;
            finishEvent += parent.finishhandler;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (finishEvent != null)
                finishEvent(this);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Item i = new Item();
                i.upcnum = int.Parse(textBox1.Text);
                if (MessageBox.Show("Is this a new item?", 
                    "Query", MessageBoxButtons.YesNo) 
                    == DialogResult.Yes)
                {
                    ItemForm form = new ItemForm(parent, i);
                    form.ShowDialog();
                    if (form.DialogResult == DialogResult.Yes)
                    {
                        //pause for completion
                    }   
                }
                Restock r = new Restock();
                r.upcnum = i.upcnum;
                r.amount = int.Parse(textBox2.Text);

                textBox1.Text = textBox2.Text = "";

                if (restockEvent != null)
                    restockEvent(this, r);

            }
            catch(Exception error)
            {
                MessageBox.Show(error.ToString());
            }
        }
    }
}
